{% extends "base.html" %}
{% load diggpaginator %}

{% block title %}Liste des machines{% endblock %}
{% block content_title %}Liste des installations en attente.{% endblock %}
{% block image %}<img src="/media/images/oxygen/search.png" />{% endblock %}
{% block extrajs %}
  {{ block.super }}
  <script type="text/javascript" charset="utf-8">
    dojo.require("dijit.Menu");

    dojo.addOnLoad(function(){
      dojo.forEach(dojo.query(".clickable_rows"), function(row)
      {
        create_menu(row.id);
      });
    });

    function create_menu(target_id) {
      pMenu = new dijit.Menu({
          targetNodeIds: [target_id,],
      });
      target_id = target_id.replace("ord_","");
      pMenu.addChild(new dijit.MenuItem({
            label: "Éditer cet ordre",
            iconClass: "dijitEditorIcon dijitEditorIconSave",
            onClick: function() {
              document.location.href = "{% url host_install.modify 1337 %}".replace("1337", target_id);},
      }));
      pMenu.addChild(new dijit.MenuItem({
            label: "Suprimer cet ordre",
            iconClass: "dijitEditorIcon dijitEditorIconDelete",
            onClick: function() {
              confirmDialog("Supression de l hote", "Êtes vous sûr de vouloir supprimer cette machine de la base?",
                function(arg, url){
                  if(arg)
                    postwith({submit_button: "delete"}, url);
                },
                "{% url host_install.modify 1337 %}".replace("1337", target_id)
            )},
      }));
      pMenu.startup();
    }
  </script>
{% endblock %}
{% block content %}
<form method='post'>
  {% csrf_token %}
  <fieldset class="block form">
    <table class="search">
     {{ form.as_column_table }}
    </table>
    <div align='center'>
      <button type="submit"  dojoType="dijit.form.Button" iconClass="dijitrtl dijitIconSearch">Rechercher</button>
    </div>
  </fieldset>
</form>
  {% if orders.object_list %}
    {% load getattribute %}
    {% if orders.paginator.num_pages > 1 %}
      {% diggpaginator orders %}
    {% endif %}
    <table class="resultat exportable" id="clariadmin_result_all">
      <thead>
        <tr>{%for column in columns %}
          <th><a href="?sort={% if sort == column %}-{% endif %}{{ column }}">{% if sort == column %}
              <img src="/media/images/oxygen/arrow-up.png" class="state_image" alt="down" />{% else %}{% if sort == '-'|add:column %}
              <img src="/media/images/oxygen/arrow-down.png" class="state_image" alt="up" />{% endif %}{% endif %}
            {{ column }}</a></th>{% endfor %}
        </tr>
      </thead>
      <tbody id="context_lines">
          {% for row in orders.object_list %}
          <tr id='ord_{{ row.id }}' class='{% cycle 'row1' 'row2'%} clickable_rows'>{% for column in columns %}
            {% if column == 'hostname' %}
            <td><a href='{% url host_install.views.modify row.id %}'>{{ row.hostname }}</a></td>
            {% else %}{% if column == 'status' %}<td style="background-color:{{ row.status_color }}">{{ row.status_text }}</td>
            {% else %}<td>{{ row|getattribute:column }}</td> {% endif %}{% endif %}
          {% endfor %}
        </tr>{% endfor %}
      </tbody>
    </table>
    {% if orders.paginator.num_pages > 1 %}
      {% diggpaginator orders %}
    {% endif %}
  {% endif %}
{% endblock %}
